package com.example.mylibrary.testActivity;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.example.mylibrary.testActivity.green.DaoMaster;
import com.example.mylibrary.testActivity.green.DaoSession;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;
import com.tencent.bugly.crashreport.CrashReport;

public class module_application {
    private DaoMaster.DevOpenHelper mHelper;
    private SQLiteDatabase db;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    public static  module_application application;
    private  module_application(){}
    public static module_application getApplication() {
        if (application == null)
            return application = new module_application();
        return application;
    }
    public void module_application_logger(final Boolean IsShow){
        //logger 初始化
        FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(false)      //（可选）是否显示线程信息。 默认值为true
                .methodCount(3)               // （可选）要显示的方法行数。 默认2
                .methodOffset(0)               // （可选）设置调用堆栈的函数偏移值，0的话则从打印该Log的函数开始输出堆栈信息，默认是0
                .tag("Logger")                  //（可选）每个日志的全局标记。 默认PRETTY_LOGGER
                .build();
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy){
            @Override public boolean isLoggable(int priority, String tag) {
                return IsShow;
            }
        });
    }
    public void module_application_bugly(Context context ,String ID){
        CrashReport.initCrashReport(context, ID, false);
    }
    /**
     * 设置greenDao
     */
    public void module_application_setDatabase(Context context,String name) {
        mHelper = new DaoMaster.DevOpenHelper(context, name + ".db", null);
        db = mHelper.getWritableDatabase();
        // 注意：该数据库连接属于 DaoMaster，所以多个 Session 指的是相同的数据库连接。
        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
    }
    public DaoSession getDaoSession() {
        return mDaoSession;
    }
    public SQLiteDatabase getDb() {
        return db;
    }
}
